/*	Rais_DXMotor.h: 笃行科技Uno扩展板的电机驱动库.
	笃行科技(DuXing, DotionBlock)
	Created:  2020.3.25
	by Raiscies.
	
	Motor: |  speed(A) |  dir(D) |			dir控制马达转向(LOW为正向, HIGH为反向)
	M1	   |  6        |  7      |			speed控制马达转速(0 ~ 255)	//method run() : -255 ~ 255
	M2     |  5        |  4      |
	
*/

#ifndef RAIS_DXMOTOR_H
#define RAIS_DXMOTOR_H

#include <Arduino.h>

class DXMotor{
	private:
	byte dirPin;	 
	byte speedPin;
	
	int speed;	//range: -255 ~ 255
	
	DXMotor(byte speedPin, byte dirPin);
	
	static void setFrequency();
	
	public:
	// M1(6, 7)   M2(5, 4)
	
	static DXMotor& getM1();
	static DXMotor& getM2();
	
	void run(int dir_speed);		//dir_speed 用正负号表示马达转向
	void operator= (int dir_speed){run(dir_speed); 		}
	void operator()(int dir_speed){run(dir_speed);			}
	void operator+=(int dir_speed){run(speed + dir_speed);	}
	void operator-=(int dir_speed){run(speed - dir_speed);	}

	int getSpeed();
	operator int(){return speed; }
};

extern DXMotor& M1;
extern DXMotor& M2;


#endif